package com.haojii.twittertranslate;

import java.util.logging.Logger;

import javax.jdo.PersistenceManager;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
 
public class StatusEntityUtils {

	private static final Logger log = Logger.getLogger(StatusEntityUtils.class.getName());
	
	public static boolean checkIfExist(long kid)
	{
		Key key = KeyFactory.createKey(StatusEntity.class.getSimpleName(), kid); 
		PersistenceManager pm = PMF.get().getPersistenceManager();
		
		StatusEntity e;
		boolean result = false;
		try {
			e = pm.getObjectById(StatusEntity.class, key);
			result = (e!=null);
		} catch (javax.jdo.JDOObjectNotFoundException e2) {
			// object not exist
			result = false;
		}
		
		pm.close();
		return result;
	} 
	
	public static void save(long kid,String status)
	{
		StatusEntity se = new StatusEntity();
		Key key = KeyFactory.createKey(StatusEntity.class.getSimpleName(), kid); 
		se.setKey(key);
		se.setStatus(status);
		log.info("save:"+se.getKey().getId()+" "+se.getStatus());
		PersistenceManager pm = PMF.get().getPersistenceManager();
		pm.makePersistent(se);
		pm.close();
	}
	
}
